package com.stox.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.stox.dto.web.Response;
import com.stox.manager.ScripManager;
import com.stox.model.Scrip;

@RestController
@RequestMapping(value="/scrips")
public class ScripController {

	@Autowired
	private ScripManager scripManager;
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.GET, produces="application/json")
	public Response<List<Scrip>> findByExchangeId(@RequestParam("exchangeId") Long exchangeId){
		return new Response<>(scripManager.findByExchangeId(exchangeId)); 
	}
	
	@ResponseBody
	@Cacheable(value=ScripManager.cacheName, key="'ScripController-'+#id")
	@RequestMapping(value="/{id}", method=RequestMethod.GET, produces="application/json")
	public Response<Scrip> findById(@PathVariable("id") Long id){
		return new Response<>(scripManager.findOne(id));
	}

}
